<link rel="stylesheet" type="text/css" href="__CDN__/static/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="__CDN__/static/css/forget.css"/>
<div id="content-container">
    <div class="row rowforClass">
<!--        <div class="closeCLass close-modal"> <i class="fa fa-close"></i></div>-->
        <div class="user-section  login-section col-lg-12">
            <div class="logon-tab">
                {if $site.b_logo}
                <img src="{$site.b_logo}" style="width: 150px" alt="Logo">
                {else}
                <img style="width:150px"
                     src="https://img0.baidu.com/it/u=933220220,287299241&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500"
                     alt="Logo">
                {/if}
                <p class="pclass">忘记密码</p>
            </div>
            <form id="resetpwd-form" class="form-horizontal form-layer" method="POST" action="{:url('user/forget')}">
                <div class="form-body">
                    <div class="" data-type="mobile">
                        <div>
                            <input  type="text" class="form-controlfor" id="mobile" name="mobile" value=""
                                   data-rule="required(#type-mobile:checked);mobile;remote({:url('api/validate/check_mobile_exist')}, event=resetpwd, id=0)"
                                   placeholder="输入手机号">
                            <span class="msg-box"></span>
                        </div>
                    </div>
                    <div class="">
                        <div>
                            <div class="codeC">
                                <div>
                                    <input class="colmd7"  type="text" name="captcha" placeholder="输入验证码" class="form-control"
                                           data-rule="required"/>
                                </div>
                                <div>
                                    <button id="sendCodeBtn1" type="button" class="colmd4" data-url="{:url('api/sms/send')}"
                                            data-type="email" data-event="[resetpwd]">发送验证码
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="">
                        <div >
                            <input type="password" class="form-controlfor" id="newpassword" name="newpassword" value=""
                                   data-rule="required;password" placeholder="输入新密码">
                            <span class="msg-box"></span>
                        </div>
                    </div>
                    <div class="">
                        <div>
                            <input type="password" class="form-controlfor" id="confirm_password" name="confirm_password" value=""
                                   data-rule="required" placeholder="确认新密码">
                            <span class="msg-box"></span>
                        </div>
                    </div>
                </div>
                <input type="hidden" id="url" name="url">

                <div class=" form-footer">
                    <div>
                        <button style="margin-top: 40px" class="btn-primaryClass" type="button" onclick="forget()" class="">提交</button>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>

<script src="__CDN__/static/js/jquery.min.js"></script>
<script src="__CDN__/static/layer/layer.js"></script>

<script>


    function forget(){
        var currentURL = window.location.href;
        console.log(currentURL);
        $("#url").val(currentURL);
        var params = $("#resetpwd-form").serialize();
        $.post("{:url('index/user/forget')}", params, function (res) {
            if (res.code == 1) {
                layer.msg(res.msg,{time: 2000,}, function () {
                    layer.closeAll();//疯狂模式，关闭所有层
                    location.href=res.url;
                })
            } else {
                layer.msg(res.msg);
                return;
            }
        })
    }

    $(document).ready(function () {
        // 给发送验证码按钮绑定点击事件
        $('#sendCodeBtn1').click(function () {


            $.post("{:url('api/sms/send')}",{mobile:$("#mobile").val(),event:'resetpwd'},function (res){
                if(res.code==1){
                    layer.msg(res.msg);

                    // 禁用按钮
                    $("#sendCodeBtn1").prop('disabled', true);
                    let countdown = 60; // 设置倒计时时间（秒）
                    let timer = setInterval(function () {
                        // 更新按钮文本显示倒计时
                        $('#sendCodeBtn1').text(countdown + '秒后可重新发送');
                        countdown--;
                        if (countdown < 0) {
                            clearInterval(timer);
                            // 倒计时结束，恢复按钮文本和可点击状态
                            $('#sendCodeBtn1').text('发送验证码');
                            $('#sendCodeBtn1').prop('disabled', false);
                        }
                    }, 1000);
                }else {
                    layer.msg(res.msg);
                    return;
                }
            })


        });

    });
</script>
